package jike.demo18.code02;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @param
 * @author oyz
 * @version 1.0.4
 * @description:TODO
 * @date 2023/3/21 21:40
 */
public class ScheduledUpdater {

    private final ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();


    private long initialDelay;
    private long period;
    private Updater updater;

    public ScheduledUpdater(long initialDelay, long period, Updater updater) {
        this.initialDelay = initialDelay;
        this.period = period;
        this.updater = updater;
    }

    public void run(){
        executorService.scheduleAtFixedRate(() -> {
            // 执行更新配置文件的逻辑
            updater.update();
        },initialDelay,period, TimeUnit.SECONDS);
    }
}
